home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume17 / parseargs / part01 < prev    next >
Encoding:
Internet Message Format  |  1991-03-17  |  61.3 KB

  1. From: brad@hcx1.ssd.csd.harris.com (Brad Appleton)
  2. Newsgroups: comp.sources.misc
  3. Subject: v17i046:  parseargs - functions to parse command line arguments, Part01/12
  4. Message-ID: <1991Mar17.200528.17700@sparky.IMD.Sterling.COM>
  5. Date: 17 Mar 91 20:05:28 GMT
  6. Approved: kent@sparky.imd.sterling.com
  7. X-Checksum-Snefru: 67348c27 4ec637b0 c16ac7e1 82a8f919
  8.  
  9. Submitted-by: Brad Appleton <brad@hcx1.ssd.csd.harris.com>
  10. Posting-number: Volume 17, Issue 46
  11. Archive-name: parseargs/part01
  12.  
  13. This is part 1 of parseargs
  14.  
  15. #!/bin/sh
  16. # This is a shell archive (produced by shar 3.49)
  17. # To extract the files from this archive, save it to a file, remove
  18. # everything above the "!/bin/sh" line above, and type "sh file_name".
  19. #
  20. # made 03/16/1991 21:25 UTC by kent@sparky.IMD.Sterling.COM
  21. # Source directory /u1/csm/queue/parseargs
  22. #
  23. # existing files will NOT be overwritten unless -c is specified
  24. #
  25. # This is part 1 of a multipart archive                                    
  26. # do not concatenate these parts, unpack them in order with /bin/sh        
  27. #
  28. # This shar contains:
  29. # length  mode       name
  30. # ------ ---------- ------------------------------------------
  31. #   5018 -rw-rw-r-- parseargs/Intro
  32. #   4033 -rw-rw-r-- parseargs/MANIFEST
  33. #   4516 -rw-rw-r-- parseargs/Makefile
  34. #   7778 -rw-rw-r-- parseargs/Makefile.cpp
  35. #  41278 -rw-rw-r-- parseargs/README
  36. #  16890 -rw-rw-r-- parseargs/amiga_args.c
  37. #   5961 -rw-rw-r-- parseargs/arglist.c
  38. #  22590 -rw-rw-r-- parseargs/argtype.c
  39. #   7427 -rw-rw-r-- parseargs/argtype3.txt
  40. #   2300 -rw-rw-r-- parseargs/doc/Makefile
  41. #   3591 -rw-rw-r-- parseargs/doc/arg_macros.inc
  42. #   3543 -rw-rw-r-- parseargs/doc/argdesc.inc
  43. #   5228 -rw-rw-r-- parseargs/doc/argflags.inc
  44. #   7204 -rw-rw-r-- parseargs/doc/argtype.man3
  45. #   1216 -rw-rw-r-- parseargs/doc/argvalopt.inc
  46. #   2103 -rw-rw-r-- parseargs/doc/bugs.inc
  47. #   1768 -rw-rw-r-- parseargs/doc/caveats.inc
  48. #   1627 -rw-rw-r-- parseargs/doc/cmd_macros.inc
  49. #   1093 -rw-rw-r-- parseargs/doc/defargs.inc
  50. #   1979 -rw-rw-r-- parseargs/doc/env_args.inc
  51. #   3224 -rw-rw-r-- parseargs/doc/env_parse.inc
  52. #   2820 -rw-rw-r-- parseargs/doc/env_usage.inc
  53. #    937 -rw-rw-r-- parseargs/doc/fparseargs3.inc
  54. #   1101 -rw-rw-r-- parseargs/doc/lib_bugs.inc
  55. #    428 -rw-rw-r-- parseargs/doc/lparseargs3.inc
  56. #   4932 -rw-rw-r-- parseargs/doc/multivals.inc
  57. #  12151 -rw-rw-r-- parseargs/doc/parseargs.man1
  58. #   9554 -rw-rw-r-- parseargs/doc/parseargs.man3
  59. #   1461 -rw-rw-r-- parseargs/doc/parseargs1.inc
  60. #    642 -rw-rw-r-- parseargs/doc/parseargs3.inc
  61. #    974 -rw-rw-r-- parseargs/doc/parsecntl.man3
  62. #   1721 -rw-rw-r-- parseargs/doc/parsecntl3.inc
  63. #   4875 -rw-rw-r-- parseargs/doc/parsecntls.inc
  64. #   5108 -rw-rw-r-- parseargs/doc/parseflags.inc
  65. #   1427 -rw-rw-r-- parseargs/doc/parsemodes.inc
  66. #   2118 -rw-rw-r-- parseargs/doc/returns.inc
  67. #   6926 -rw-rw-r-- parseargs/doc/sh_arrays.inc
  68. #   2275 -rw-rw-r-- parseargs/doc/shells.inc
  69. #    836 -rw-rw-r-- parseargs/doc/sparseargs3.inc
  70. #    449 -rw-rw-r-- parseargs/doc/usage3.inc
  71. #    737 -rw-rw-r-- parseargs/doc/vparseargs3.inc
  72. #  23858 -rw-rw-r-- parseargs/ibm_args.c
  73. #   6648 -rw-rw-r-- parseargs/parseargs.awk
  74. #  70264 -rw-rw-r-- parseargs/parseargs.c
  75. #  42981 -rw-rw-r-- parseargs/parseargs.h
  76. #   2311 -rwxrwxr-x parseargs/parseargs.pl
  77. #  33378 -rw-rw-r-- parseargs/parseargs1.txt
  78. #  37108 -rw-rw-r-- parseargs/parseargs3.txt
  79. #  17278 -rw-rw-r-- parseargs/parsecntl3.txt
  80. #  12588 -rw-rw-r-- parseargs/pgopen.c
  81. #    977 -rw-rw-r-- parseargs/pgopen.h
  82. #   9196 -rw-rw-r-- parseargs/stest.c
  83. #  34399 -rw-rw-r-- parseargs/strfuncs.c
  84. #   1729 -rw-rw-r-- parseargs/strfuncs.h
  85. #   5916 -rw-rw-r-- parseargs/syserr.c
  86. #   6643 -rwxrwxr-x parseargs/test.awk
  87. #   2023 -rwxrwxr-x parseargs/test.csh
  88. #   2097 -rwxrwxr-x parseargs/test.ksh
  89. #   1718 -rwxrwxr-x parseargs/test.pl
  90. #   1728 -rwxrwxr-x parseargs/test.rc
  91. #   1789 -rwxrwxr-x parseargs/test.sh
  92. #  20417 -rw-rw-r-- parseargs/unix_args.c
  93. #   7749 -rw-rw-r-- parseargs/unix_man.c
  94. #   7432 -rw-rw-r-- parseargs/useful.h
  95. #  30360 -rw-rw-r-- parseargs/vms_args.c
  96. #   8146 -rw-rw-r-- parseargs/vprintf.c
  97. #   7121 -rw-rw-r-- parseargs/winsize.c
  98. #  70930 -rw-rw-r-- parseargs/xparse.c
  99. #
  100. if test -r _shar_seq_.tmp; then
  101.     echo 'Must unpack archives in sequence!'
  102.     echo Please unpack part `cat _shar_seq_.tmp` next
  103.     exit 1
  104. fi
  105. # ============= parseargs/Intro ==============
  106. if test ! -d 'parseargs'; then
  107.     echo 'x - creating directory parseargs'
  108.     mkdir 'parseargs'
  109. fi
  110. if test -f 'parseargs/Intro' -a X"$1" != X"-c"; then
  111.     echo 'x - skipping parseargs/Intro (File already exists)'
  112.     rm -f _shar_wnt_.tmp
  113. else
  114. > _shar_wnt_.tmp
  115. echo 'x - extracting parseargs/Intro (Text)'
  116. sed 's/^X//' << 'SHAR_EOF' > 'parseargs/Intro' &&
  117. X
  118. X                                  PARSEARGS
  119. X
  120. X                        extracted from Eric Allman's
  121. X
  122. X                            NIFTY UTILITY LIBRARY
  123. X
  124. X                          Created by Eric P. Allman
  125. X                             <eric@Berkeley.EDU>
  126. X
  127. X                         Modified by Peter da Silva
  128. X                            <peter@Ferranti.COM>
  129. X
  130. X                   Modified and Rewritten by Brad Appleton
  131. X                          <brad@SSD.CSD.Harris.COM>
  132. X
  133. X
  134. X Welcome to parseargs! Dont let the initial size of this package scare you.
  135. X over 75% of it is English text, and more than 50% of the source is comments.
  136. X
  137. X Parseargs is a set of functions to parse command-line arguments. Unlike
  138. X getopt and its variants, parseargs does more than just split up the
  139. X command-line into some canonical form. Parseargs will actually parse the
  140. X command-line, assigning the appropriate command-line values to the
  141. X corresponding variables, and will verify the command-line syntax (and print
  142. X a usage message if necessary). Furthermore, many features of it's parsing
  143. X behavior are configurable at run-time. Some of these features include the
  144. X following:
  145. X
  146. X     o  Prompting the user for missing arguments
  147. X     o  Allowing keywords (+count=4) and/or options (-c4)
  148. X     o  Checking for default arguments in an environment variable
  149. X     o  Ignoring bad syntax instead of terminating
  150. X     o  Ignoring upper/lower case on the command-line
  151. X     o  Controlling the location of non-positional parameters
  152. X     o  Controlling the contents (syntax and verbosity) of usage messages
  153. X     o  Having long usage messages piped through a paging program
  154. X
  155. X Parseargs also allows for options that take an optional argument, and
  156. X options that take a (possibly optional) list of one or more arguments.
  157. X In addition, parseargs may be configured at compile-time to parse
  158. X command-lines in accordance with the native command-syntax of any of the
  159. X following operating systems:
  160. X
  161. X     o  Unix
  162. X     o  VAX/VMS
  163. X     o  OS/2
  164. X     o  MS-DOS
  165. X     o  AmigaDOS
  166. X
  167. X Parseargs consists of a set of C-functions to parse arguments from the
  168. X command-line, from files, from strings, from linked-lists, and from
  169. X string-vectors. Also included is a command-line interface which will parse
  170. X arguments for shell scripts (sh, csh/tcsh, ksh, bash, and rc), awk-scripts,
  171. X and perl-scripts.
  172. X
  173. X The basic structure used by parseargs is the argument-descriptor (sometimes
  174. X called "argdesc" for brevity).  An array/string of argdescs is declared by
  175. X the user to describe the command in question.  The resulting argdesc-array
  176. X is passed to all the parseargs functions and is used to hold all information
  177. X about the command. a sample argdesc-array is shown below.
  178. X
  179. X    STARTOFARGS,
  180. X    { 'a', ARGVALOPT, argStr,   &area,    "AREAcode : optional area-code" },
  181. X    { 'g', ARGLIST,   argStr,   &groups,  "newsGROUPS : groups to test" },
  182. X    { 'r', ARGOPT,    argInt,   &count,   "REPcount : repetition factor" },
  183. X    { 's', ARGOPT,    argChar,  &sepch,   "SEPchar : field separator" },
  184. X    { 'x', ARGOPT,    argBool,  &xflag,   "Xflag : turn on X-mode" },
  185. X    { ' ', ARGREQ,    argStr,   &name,    "name : name to use" },
  186. X    { ' ', ARGLIST,   argStr,   &args,    "args : any remaining arguments" },
  187. X    ENDOFARGS
  188. X
  189. X Once the above array/string is declared it is a simple matter to invoke
  190. X parseargs from C as in the following example:
  191. X
  192. X    status = parseargs( argdesc_array, argv );
  193. X
  194. X or from a shell script as in the following example:
  195. X
  196. X    echo "$ARGDESC_STR" | parseargs -s sh -- "$0" "$@" >tmp$$
  197. X    if [ $? = 0 ] ; then
  198. X       . tmp$$
  199. X    fi
  200. X    /bin/rm -f tmp$$
  201. X
  202. X And before you know it, your command-line had been parsed, all variables 
  203. X have been assigned their corresponding values from the command-line, syntax
  204. X has been verified, and a usage message (if required) has been printed. 
  205. X
  206. X Under UNIX, the command-line syntax (using single character options) for the
  207. X above command would be:
  208. X
  209. X    cmdname [-a [<areacode>]] [-g <newsgroups>...] [-r <repcount>]
  210. X            [-s <sepchar>] [-x]  <name>  [<args>...]
  211. X
  212. X The UNIX command-line syntax using keywords (or long options) would be:
  213. X
  214. X    cmdname [+area [<areacode>]] [+groups <newsgroups>...] [+rep <repcount>]
  215. X            [+sep <sepchar>] [+x]  <name>  [<args>...]
  216. X
  217. X The VMS command-line syntax would be the following:
  218. X
  219. X    cmdname [/AREA[=<areacode>]] [/GROUPS=<newsgroups>[,<newsgroups>...]
  220. X            [/REP=<repcount>] [/SEP=<sepchar>] [/X]  <name>
  221. X            [<args>[,<args>...]]
  222. X
  223. X The MS-DOS and OS/2 command-line syntax would be the following (unless the
  224. X environment variable $SWITCHAR is '-' in which case UNIX syntax is used):
  225. X
  226. X    cmdname [/a[=<areacode>]] [/g=<newsgroups>...] [/r=<repcount>]
  227. X            [/s=<sepchar>] [/x]  <name>  [<args>...]
  228. X
  229. X  The AmigaDOS command-line syntax would be the following:
  230. X
  231. X    cmdname [AREA [<areacode>]] [GROUPS <newsgroups>...] [REP <repcount>]
  232. X            [SEP <sepchar>] [X]  <name>  [<args>...]
  233. X
  234. X
  235. X Please look at the README files and manpages for more detailed information!
  236. SHAR_EOF
  237. chmod 0664 parseargs/Intro ||
  238. echo 'restore of parseargs/Intro failed'
  239. Wc_c="`wc -c < 'parseargs/Intro'`"
  240. test 5018 -eq "$Wc_c" ||
  241.     echo 'parseargs/Intro: original size 5018, current size' "$Wc_c"
  242. rm -f _shar_wnt_.tmp
  243. fi
  244. # ============= parseargs/MANIFEST ==============
  245. if test -f 'parseargs/MANIFEST' -a X"$1" != X"-c"; then
  246.     echo 'x - skipping parseargs/MANIFEST (File already exists)'
  247.     rm -f _shar_wnt_.tmp
  248. else
  249. > _shar_wnt_.tmp
  250. echo 'x - extracting parseargs/MANIFEST (Text)'
  251. sed 's/^X//' << 'SHAR_EOF' > 'parseargs/MANIFEST' &&
  252. X   File Name        Archive #    Description
  253. -----------------------------------------------------------
  254. X Intro                      2    Introduction to parseargs
  255. X MANIFEST                   1    This file
  256. X Makefile                   2    makefile for parseargs library
  257. X Makefile.cpp               3    makefile template read by the C preprocessor
  258. X README                     1    release information
  259. X amiga_args.c               4    parse AmigaDOS command-lines
  260. X arglist.c                  2    implement the listXxxx functions for arglists
  261. X argtype.c                  5    implement the argXxxx argument type functions
  262. X doc/                       1    directory containing documentation
  263. X doc/Makefile               2    makefile for the documentation
  264. X doc/arg_macros.inc         2    describe arg-xxx and ARG_XXX macros
  265. X doc/argdesc.inc            2    describe an ARGDESC structure
  266. X doc/argflags.inc           2    describe argument flags
  267. X doc/argtype.man3           3    {n,t}roff source for argtype(3)
  268. X doc/argvalopt.inc          1    describe options with optional arguments
  269. X doc/bugs.inc               2    BUGS section for parseargs(1)
  270. X doc/caveats.inc            1    CAVEATS section for parseargs(1) and (3)
  271. X doc/cmd_macros.inc         1    describe CMD_XXX macros
  272. X doc/defargs.inc            1    describe the default argdesc-array
  273. X doc/env_args.inc           1    describe use of $CMD_ARGS
  274. X doc/env_parse.inc          2    describe use of $PARSECNTL
  275. X doc/env_usage.inc          2    describe use of $USAGECNTL
  276. X doc/fparseargs3.inc        1    describe fparseargs(3)
  277. X doc/lib_bugs.inc           1    BUGS section for parseargs(3)
  278. X doc/lparseargs3.inc        1    describe lparseargs(3)
  279. X doc/multivals.inc          2    describe multivals(3)
  280. X doc/parseargs.man1         4    {n,t}roff source for parseargs(1)
  281. X doc/parseargs.man3         4    {n,t}roff source for parseargs(3)
  282. X doc/parseargs1.inc         1    describe parseargs(1)
  283. X doc/parseargs3.inc         1    describe parseargs(3)
  284. X doc/parsecntl.man3         1    {n,t}roff source for parsecntl(3)
  285. X doc/parsecntl3.inc         1    describe parsecntl(3)
  286. X doc/parsecntls.inc         2    describe function-codes for parsecntl(3)
  287. X doc/parseflags.inc         2    describe parse flags
  288. X doc/parsemodes.inc         1    describe modes for parsecntl(3)
  289. X doc/returns.inc            2    describe function return values
  290. X doc/sh_arrays.inc          3    describe handling of shell arrays
  291. X doc/shells.inc             2    describe handling of different shells
  292. X doc/sparseargs3.inc        1    describe sparseargs(3)
  293. X doc/usage3.inc             1    describe usage(3)
  294. X doc/vparseargs3.inc        1    describe vparseargs(3)
  295. X ibm_args.c                 5    parse MS-DOS and OS/2 command-lines
  296. X parseargs.awk              3    parseargs for awk
  297. X parseargs.c                7    C source for parseargs(1)
  298. X parseargs.h                6    include file for parseargs library
  299. X parseargs.pl               2    parseargs for perl
  300. X pgopen.c                   4    pipe output to a pager
  301. X pgopen.h                   1    include file for pgopen.c
  302. X stest.c                    3    test progarm for parseargs(3)
  303. X strfuncs.c                 6    string library
  304. X strfuncs.h                 1    include file for strfuncs.c
  305. X syserr.c                   2    diagnostic message printing routines
  306. X test.awk                   3    awk test program for parseargs(1)
  307. X test.csh                   2    C-shell test program for parseargs(1)
  308. X test.ksh                   2    Korn shell test program for parseargs(1)
  309. X test.pl                    1    perl test program for parseargs(1)
  310. X test.rc                    1    Plan 9 shell test program for parseargs(1)
  311. X test.sh                    1    Bourne shell test program for parseargs(1)
  312. X unix_args.c                4    parse Unix command-lines
  313. X unix_man.c                 3    print Unix manual-page templates
  314. X useful.h                   3    common include file for the library
  315. X vms_args.c                 5    parse VAX/VMS DCL command-lines
  316. X vprintf.c                  3    portable vfprintf, vprintf, and vsprintf
  317. X winsize.c                  3    determine # rows and # columns of window
  318. X xparse.c                   8    implement the parseargs library
  319. SHAR_EOF
  320. chmod 0664 parseargs/MANIFEST ||
  321. echo 'restore of parseargs/MANIFEST failed'
  322. Wc_c="`wc -c < 'parseargs/MANIFEST'`"
  323. test 4033 -eq "$Wc_c" ||
  324.     echo 'parseargs/MANIFEST: original size 4033, current size' "$Wc_c"
  325. rm -f _shar_wnt_.tmp
  326. fi
  327. # ============= parseargs/Makefile ==============
  328. if test -f 'parseargs/Makefile' -a X"$1" != X"-c"; then
  329.     echo 'x - skipping parseargs/Makefile (File already exists)'
  330.     rm -f _shar_wnt_.tmp
  331. else
  332. > _shar_wnt_.tmp
  333. echo 'x - extracting parseargs/Makefile (Text)'
  334. sed 's/^X//' << 'SHAR_EOF' > 'parseargs/Makefile' &&
  335. # $Header: Makefile,v 2.1 89/12/30 20:59:01 eric Exp $
  336. X
  337. ###
  338. # operating-system dependent stuff
  339. ###
  340. .UNIVERSE =    att
  341. #.UNIVERSE =    ucb
  342. OS_TYPE =    unix
  343. # OS_DEFS =    -D${OS_TYPE} -D${.UNIVERSE}_universe
  344. X
  345. ###
  346. # targets
  347. ###
  348. NAME =    parseargs
  349. PROGRAM =    ${NAME}
  350. LIBRARY =    ${NAME}
  351. STYLE =    unix
  352. X
  353. ###
  354. # target directories
  355. ###
  356. LOCAL =  /usr/local
  357. LIBDIR = ${LOCAL}/lib
  358. INCDIR = ${LOCAL}/include
  359. X
  360. ###
  361. # compilation options
  362. ###
  363. INCLUDES =    -I.
  364. # MODEL =    -Ms
  365. # MODELNAME =    S
  366. OPT =    -O
  367. # OPT =    -g
  368. TEST_DEFS =    
  369. USR_DEFS =    -DUSE_PAGER
  370. DEFINES =    ${OS_DEFS} ${USR_DEFS} ${TEST_DEFS} -D${STYLE}_style
  371. OPTIONS =
  372. CFLAGS =    ${OPT} ${MODEL} ${INCLUDES} ${DEFINES} ${OPTIONS}
  373. LINTFLAGS =    ${INCLUDES} ${DEFINES} ${OPTIONS}
  374. X
  375. ###
  376. # libraries
  377. ###
  378. LIBARGS =    ${MODELNAME}lib${STYLE}_args.a
  379. LIBFILE =    ${MODELNAME}libparse.a
  380. LOCLIBS =    ${LIBARGS}
  381. # SYSLIBS =    -lm -lcurses -ltermcap
  382. LIBS =    ${LOCLIBS} ${SYSLIBS}
  383. X
  384. ###
  385. # commands
  386. ###
  387. AR =    ar rvu
  388. DEL =    rm -f
  389. COPY =    cp
  390. CHDIR =    cd
  391. LINT =    lint
  392. MKTAGS =    ctags
  393. PRINT =    pr
  394. RANLIB =    ranlib
  395. SHAR =    shar
  396. SQZ =    compress -v
  397. X
  398. ###
  399. # files used
  400. ###
  401. DOCS=    doc/Makefile \
  402. X        doc/argtype.man3 \
  403. X        doc/parseargs.man1 \
  404. X        doc/parseargs.man3 \
  405. X        doc/parsecntl.man3 \
  406. X        doc/arg_macros.inc \
  407. X        doc/argdesc.inc \
  408. X        doc/argflags.inc \
  409. X        doc/argvalopt.inc \
  410. X        doc/bugs.inc \
  411. X        doc/caveats.inc \
  412. X        doc/cmd_macros.inc \
  413. X        doc/defargs.inc \
  414. X        doc/env_args.inc \
  415. X        doc/env_parse.inc \
  416. X        doc/env_usage.inc \
  417. X        doc/fparseargs3.inc \
  418. X        doc/lib_bugs.inc \
  419. X        doc/lparseargs3.inc \
  420. X        doc/multivals.inc \
  421. X        doc/parseargs1.inc \
  422. X        doc/parseargs3.inc \
  423. X        doc/parsecntl3.inc \
  424. X        doc/parsecntls.inc \
  425. X        doc/parseflags.inc \
  426. X        doc/parsemodes.inc \
  427. X        doc/returns.inc \
  428. X        doc/sh_arrays.inc \
  429. X        doc/shells.inc \
  430. X        doc/sparseargs3.inc \
  431. X        doc/usage3.inc \
  432. X        doc/vparseargs3.inc
  433. SCRIPTS =    test.sh  test.csh  test.ksh  test.rc  test.awk  test.pl
  434. TEMPLATES =    ${NAME}.pl  ${NAME}.awk
  435. XXXFILES =    Intro  README  MANIFEST  Makefile  Makefile.cpp
  436. X
  437. HDRS =    ${NAME}.h \
  438. X        pgopen.h \
  439. X        strfuncs.h \
  440. X        useful.h
  441. X
  442. SRCS =    ${NAME}.c \
  443. X        argtype.c \
  444. X        arglist.c \
  445. X        amiga_args.c \
  446. X        ibm_args.c \
  447. X        pgopen.c \
  448. X        stest.c \
  449. X        strfuncs.c \
  450. X        syserr.c \
  451. X        unix_args.c \
  452. X        unix_man.c \
  453. X        vms_args.c \
  454. X        vprintf.c \
  455. X        winsize.c \
  456. X        xparse.c
  457. X
  458. OBJS =  ${STYLE}_args.o \
  459. X         arglist.o \
  460. X         argtype.o \
  461. X         pgopen.o \
  462. X         strfuncs.o \
  463. X         syserr.o \
  464. X         vprintf.o \
  465. X         winsize.o \
  466. X         xparse.o
  467. X
  468. PROG_OBJS =  ${NAME}.o   unix_man.o
  469. TEST_OBJS =  stest.o
  470. X
  471. FILES =    ${XXFILES} ${DOCS} ${HDRS} ${SRCS} ${TEMPLATES} ${SCRIPTS}
  472. X
  473. ###
  474. # target dependencies
  475. ###
  476. all: ${LIBARGS} test ${PROGRAM}
  477. X
  478. test: ${STYLE}_test
  479. X
  480. ${STYLE}_test :  stest.o ${LOCLIBS}
  481. X    ${CC} ${CFLAGS} -o ${STYLE}_test  stest.o ${LOCLIBS} ${SYSLIBS}
  482. X
  483. ${LIBARGS}: ${OBJS}
  484. X    ${AR} $@ ${OBJS}
  485. X    ${RANLIB} $@
  486. X
  487. ${PROGRAM}: ${PROG_OBJS} ${LOCLIBS}
  488. X    ${CC} ${CFLAGS} -o $@ ${PROG_OBJS} ${LOCLIBS} ${SYSLIBS}
  489. X
  490. ###
  491. # object dependencies
  492. ###
  493. ${NAME}.o:    ${NAME}.c ${NAME}.h strfuncs.h useful.h
  494. amiga_args.o:    amiga_args.c ${NAME}.h pgopen.h strfuncs.h useful.h
  495. arglist.o:    arglist.c ${NAME}.h strfuncs.h useful.h
  496. argtype.o:    argtype.c ${NAME}.h strfuncs.h useful.h
  497. ibm_args.o:    ibm_args.c ${NAME}.h pgopen.h strfuncs.h useful.h
  498. pgopen.o:    pgopen.c useful.h
  499. stest.o:    stest.c ${NAME}.h useful.h
  500. strfuncs.o:    strfuncs.c useful.h
  501. syserr.o:    syserr.c useful.h
  502. unix_args.o:    unix_args.c ${NAME}.h pgopen.h strfuncs.h useful.h
  503. unix_man.o:    unix_man.c ${NAME}.h strfuncs.h useful.h
  504. vms_args.o:    vms_args.c ${NAME}.h pgopen.h strfuncs.h useful.h
  505. vprintf.o:    vprintf.c useful.h
  506. winsize.o:    winsize.c useful.h
  507. xparse.o:    xparse.c ${NAME}.h strfuncs.h useful.h
  508. X
  509. ###
  510. # installation dependencies
  511. ###
  512. install:  ${INCDIR}/${NAME}.h \
  513. X         ${LIBDIR}/${LIBFILE} \
  514. X         ${LOCAL}/${PROGRAM}
  515. X
  516. X ${INCDIR}/${NAME}.h: ${NAME}.h useful.h
  517. X    ( ${CHDIR} ${INCDIR}; ${DEL} ${NAME}.h useful.h )
  518. X    ${COPY} ${NAME}.h useful.h ${INCDIR}
  519. X
  520. X ${LIBDIR}/${LIBFILE}: ${LIBARGS}
  521. X    ${DEL}   ${LIBDIR}/${LIBFILE}
  522. X    ${COPY} ${LIBARGS}   ${LIBDIR}/${LIBFILE}
  523. X    ${RANLIB}   ${LIBDIR}/${LIBFILE}
  524. X
  525. X ${LOCAL}/${PROGRAM}: ${PROGRAM} ${TEMPLATES}
  526. X    ( ${CHDIR} ${LOCAL} ; ${DEL} ${PROGRAM} ${TEMPLATES} )
  527. X    ${COPY} ${PROGRAM} ${TEMPLATES} ${LOCAL}
  528. X
  529. ###
  530. # maintenance dependencies
  531. ###
  532. lint: ${SRCS}
  533. X    ${LINT} ${LINTFLAGS} ${SRCS}
  534. X
  535. shar: ${NAME}.shar
  536. X
  537. ${NAME}.shar: ${FILES}
  538. X    ${DEL} ${NAME}.shar
  539. X    ${SHAR} ${FILES}  >${NAME}.shar
  540. X
  541. clean:
  542. X    ${DEL} ${OBJS} ${PROG_OBJS} ${TEST_OBJS}
  543. X    ${DEL} tags core .exrc
  544. X
  545. clobber: clean
  546. X    ${DEL} ${LIBARGS}  ${PROGRAM}  ${STYLE}_test
  547. X
  548. tags: ${SRCS} ${HDRS}
  549. X    ${MKTAGS} ${SRCS} ${HDRS}
  550. X
  551. collapse: clobber shar
  552. X    ${SQZ} ${NAME}.shar
  553. X    ${DEL} ${FILES}
  554. X
  555. print: ${SRCS} ${HDRS}
  556. X    @${PRINT} ${SRCS} ${HDRS}
  557. X
  558. SHAR_EOF
  559. chmod 0664 parseargs/Makefile ||
  560. echo 'restore of parseargs/Makefile failed'
  561. Wc_c="`wc -c < 'parseargs/Makefile'`"
  562. test 4516 -eq "$Wc_c" ||
  563.     echo 'parseargs/Makefile: original size 4516, current size' "$Wc_c"
  564. rm -f _shar_wnt_.tmp
  565. fi
  566. # ============= parseargs/Makefile.cpp ==============
  567. if test -f 'parseargs/Makefile.cpp' -a X"$1" != X"-c"; then
  568.     echo 'x - skipping parseargs/Makefile.cpp (File already exists)'
  569.     rm -f _shar_wnt_.tmp
  570. else
  571. > _shar_wnt_.tmp
  572. echo 'x - extracting parseargs/Makefile.cpp (Text)'
  573. sed 's/^X//' << 'SHAR_EOF' > 'parseargs/Makefile.cpp' &&
  574. #define REM #
  575. #define REMLINE ###
  576. X
  577. #define ECHO(x) x
  578. X
  579. #ifdef unix
  580. # define SYSTEM_NAME \unix
  581. # define SYSTEM_TYPE att
  582. # define _Output(file) >file
  583. # define _Executable(file) file
  584. # define _Library(file) file
  585. # define _Object(file) file.o
  586. # define _SubDir(d1,d2) d1/d2
  587. # define _Dir(dir) dir
  588. # define _Pathname(dir,file) dir/file
  589. # define ROOT_DIR /
  590. # define AR_CMD ar rvu
  591. # define DEL_CMD rm -f
  592. # define COPY_CMD cp
  593. # define CHDIR_CMD cd
  594. # define LINT_CMD lint
  595. # define MKTAGS_CMD ctags
  596. # define PRINT_CMD pr
  597. # define RANLIB_CMD ranlib
  598. # define SHAR_CMD shar
  599. # define SQZ_CMD compress -v
  600. #endif
  601. X
  602. #ifdef vms
  603. # define SYSTEM_NAME \vms
  604. # define SYSTEM_TYPE dec
  605. # define _Output(file) /OUTPUT=file
  606. # define _Executable(file) file.exe
  607. # define _Library(file) file
  608. # define _Object(file) file.obj
  609. # define _SubDir(d1,d2) d1.d2
  610. # define _Dir(dir) [dir]
  611. # define _Pathname(dir,file) ECHO(dir)file
  612. # define ROOT_DIR
  613. # define AR_CMD ar rvu
  614. # define DEL_CMD delete/file
  615. # define COPY_CMD copy/file
  616. # define CHDIR_CMD set/dir
  617. # define LINT_CMD lint
  618. # define MKTAGS_CMD ctags
  619. # define PRINT_CMD type
  620. # define RANLIB_CMD ranlib
  621. # define SHAR_CMD shar
  622. # define SQZ_CMD compress/file
  623. #endif
  624. X
  625. #if ( defined(AZTEC) || defined(MANX) )
  626. # define SYSTEM_NAME amiga
  627. # define SYSTEM_TYPE commodore
  628. # define _Output(file) >file
  629. # define _Executable(file) file.exe
  630. # define _Library(file) file
  631. # define _Object(file) file.obj
  632. # define _SubDir(d1,d2) d1/d2
  633. # define _Dir(dir) dir
  634. # define _Pathname(dir,file) dir/file
  635. # define ROOT_DIR /
  636. # define AR_CMD ar rvu
  637. # define DEL_CMD rm -f
  638. # define COPY_CMD cp
  639. # define CHDIR_CMD cd
  640. # define LINT_CMD lint
  641. # define MKTAGS_CMD ctags
  642. # define PRINT_CMD type
  643. # define RANLIB_CMD ranlib
  644. # define SHAR_CMD shar
  645. # define SQZ_CMD compress -v
  646. #endif
  647. X
  648. #ifdef MS_DOS
  649. # define SYSTEM_NAME dos
  650. # define SYSTEM_TYPE ibm
  651. # define _Output(file) >file
  652. # define _Executable(file) file.exe
  653. # define _Library(file) file
  654. # define _Object(file) file.obj
  655. # define _SubDir(d1,d2) d1\\d2
  656. # define _Dir(dir) dir
  657. # define _Pathname(dir,file) dir\\file
  658. # define ROOT_DIR \\
  659. # define AR_CMD ar rvu
  660. # define DEL_CMD del
  661. # define COPY_CMD copy
  662. # define CHDIR_CMD cd
  663. # define LINT_CMD lint
  664. # define MKTAGS_CMD ctags
  665. # define PRINT_CMD type
  666. # define RANLIB_CMD ranlib
  667. # define SHAR_CMD shar
  668. # define SQZ_CMD arc -c
  669. #endif
  670. X
  671. #ifdef OS2
  672. # define SYSTEM_NAME os2
  673. # define SYSTEM_TYPE ibm
  674. # define _Output(file) >file
  675. # define _Executable(file) file.exe
  676. # define _Library(file) file
  677. # define _Object(file) file.obj
  678. # define _SubDir(d1,d2) d1\\d2
  679. # define _Dir(dir) dir
  680. # define _Pathname(dir,file) dir\\file
  681. # define ROOT_DIR \\
  682. # define AR_CMD ar rvu
  683. # define DEL_CMD del
  684. # define COPY_CMD copy
  685. # define CHDIR_CMD cd
  686. # define LINT_CMD lint
  687. # define MKTAGS_CMD ctags
  688. # define PRINT_CMD type
  689. # define RANLIB_CMD ranlib
  690. # define SHAR_CMD shar
  691. # define SQZ_CMD arc -c
  692. #endif
  693. X
  694. REM $Header: Makefile,v 2.1 89/12/30 20:59:01 eric Exp $
  695. X
  696. REMLINE
  697. REM operating-system dependent stuff
  698. REMLINE
  699. .UNIVERSE =    SYSTEM_TYPE
  700. OS_TYPE =    SYSTEM_NAME
  701. REM OS_DEFS =    -D${OS_TYPE} -D${.UNIVERSE}_universe
  702. X
  703. REMLINE
  704. REM targets
  705. REMLINE
  706. NAME =    parseargs
  707. PROGRAM =    _Executable(${NAME})
  708. LIBRARY =    _Library(${NAME})
  709. STYLE =    SYSTEM_NAME
  710. X
  711. REMLINE
  712. REM target directories
  713. REMLINE
  714. LOCAL =    _Dir(_SubDir(usr,local))
  715. LIBDIR =    _Dir(_SubDir(${LOCAL},lib))
  716. INCDIR =    _Dir(_SubDir(${LOCAL},include))
  717. X
  718. REMLINE
  719. REM compilation options
  720. REMLINE
  721. INCLUDES =    -I.
  722. REM MODEL =    -Ms
  723. REM MODELNAME =    S
  724. OPT =    -O
  725. REM OPT =    -g
  726. TEST_DEFS =    
  727. USR_DEFS =    -DUSE_PAGER
  728. DEFINES =    ${OS_DEFS} ${USR_DEFS} ${TEST_DEFS} -D${STYLE}_style
  729. OPTIONS =
  730. CFLAGS =    ${OPT} ${MODEL} ${INCLUDES} ${DEFINES} ${OPTIONS}
  731. LINTFLAGS =    ${INCLUDES} ${DEFINES} ${OPTIONS}
  732. X
  733. REMLINE
  734. REM libraries
  735. REMLINE
  736. LIBARGS =    ${MODELNAME}lib${STYLE}_args.a
  737. LIBFILE =    ${MODELNAME}libparse.a
  738. LOCLIBS =    ${LIBARGS}
  739. REM SYSLIBS =    -lm -lcurses -ltermcap
  740. LIBS =    ${LOCLIBS} ${SYSLIBS}
  741. X
  742. REMLINE
  743. REM commands
  744. REMLINE
  745. AR =    AR_CMD
  746. DEL =    DEL_CMD
  747. COPY =    COPY_CMD
  748. CHDIR =    CHDIR_CMD
  749. LINT =    LINT_CMD
  750. MKTAGS =    MKTAGS_CMD
  751. PRINT =    PRINT_CMD
  752. RANLIB =    RANLIB_CMD
  753. SHAR =    SHAR_CMD
  754. SQZ =    SQZ_CMD
  755. X
  756. REMLINE
  757. REM files used
  758. REMLINE
  759. DOCS=    doc/Makefile \
  760. X        doc/argtype.man3 \
  761. X        doc/parseargs.man1 \
  762. X        doc/parseargs.man3 \
  763. X        doc/parsecntl.man3 \
  764. X        doc/arg_macros.inc \
  765. X        doc/argdesc.inc \
  766. X        doc/argflags.inc \
  767. X        doc/argvalopt.inc \
  768. X        doc/bugs.inc \
  769. X        doc/caveats.inc \
  770. X        doc/cmd_macros.inc \
  771. X        doc/defargs.inc \
  772. X        doc/env_args.inc \
  773. X        doc/env_parse.inc \
  774. X        doc/env_usage.inc \
  775. X        doc/fparseargs3.inc \
  776. X        doc/lib_bugs.inc \
  777. X        doc/lparseargs3.inc \
  778. X        doc/multivals.inc \
  779. X        doc/parseargs1.inc \
  780. X        doc/parseargs3.inc \
  781. X        doc/parsecntl3.inc \
  782. X        doc/parsecntls.inc \
  783. X        doc/parseflags.inc \
  784. X        doc/parsemodes.inc \
  785. X        doc/returns.inc \
  786. X        doc/sh_arrays.inc \
  787. X        doc/shells.inc \
  788. X        doc/sparseargs3.inc \
  789. X        doc/usage3.inc \
  790. X        doc/vparseargs3.inc
  791. SCRIPTS =    test.sh  test.csh  test.ksh  test.rc  test.awk  test.pl
  792. TEMPLATES =    ${NAME}.pl  ${NAME}.awk
  793. XXXFILES =    Intro  README  MANIFEST  Makefile  Makefile.cpp
  794. X
  795. HDRS =    ${NAME}.h \
  796. X        pgopen.h \
  797. X        strfuncs.h \
  798. X        useful.h
  799. X
  800. SRCS =    ${NAME}.c \
  801. X        argtype.c \
  802. X        arglist.c \
  803. X        amiga_args.c \
  804. X        ibm_args.c \
  805. X        pgopen.c \
  806. X        stest.c \
  807. X        strfuncs.c \
  808. X        syserr.c \
  809. X        unix_args.c \
  810. X        unix_man.c \
  811. X        vms_args.c \
  812. X        vprintf.c \
  813. X        winsize.c \
  814. X        xparse.c
  815. X
  816. OBJS = _Object(${STYLE}_args) \
  817. X        _Object(arglist) \
  818. X        _Object(argtype) \
  819. X        _Object(pgopen) \
  820. X        _Object(strfuncs) \
  821. X        _Object(syserr) \
  822. X        _Object(vprintf) \
  823. X        _Object(winsize) \
  824. X        _Object(xparse)
  825. X
  826. PROG_OBJS = _Object(${NAME})  _Object(unix_man)
  827. TEST_OBJS = _Object(stest)
  828. X
  829. FILES =    ${XXFILES} ${DOCS} ${HDRS} ${SRCS} ${TEMPLATES} ${SCRIPTS}
  830. X
  831. REMLINE
  832. REM target dependencies
  833. REMLINE
  834. all: ${LIBARGS} test ${PROGRAM}
  835. X
  836. test: ${STYLE}_test
  837. X
  838. ${STYLE}_test : _Object(stest) ${LOCLIBS}
  839. X    ${CC} ${CFLAGS} -o ${STYLE}_test _Object(stest) ${LOCLIBS} ${SYSLIBS}
  840. X
  841. ${LIBARGS}: ${OBJS}
  842. X    ${AR} $@ ${OBJS}
  843. X    ${RANLIB} $@
  844. X
  845. ${PROGRAM}: ${PROG_OBJS} ${LOCLIBS}
  846. X    ${CC} ${CFLAGS} -o $@ ${PROG_OBJS} ${LOCLIBS} ${SYSLIBS}
  847. X
  848. REMLINE
  849. REM object dependencies
  850. REMLINE
  851. ${NAME}.o:    ${NAME}.c ${NAME}.h strfuncs.h useful.h
  852. amiga_args.o:    amiga_args.c ${NAME}.h pgopen.h strfuncs.h useful.h
  853. arglist.o:    arglist.c ${NAME}.h strfuncs.h useful.h
  854. argtype.o:    argtype.c ${NAME}.h strfuncs.h useful.h
  855. ibm_args.o:    ibm_args.c ${NAME}.h pgopen.h strfuncs.h useful.h
  856. pgopen.o:    pgopen.c useful.h
  857. stest.o:    stest.c ${NAME}.h useful.h
  858. strfuncs.o:    strfuncs.c useful.h
  859. syserr.o:    syserr.c useful.h
  860. unix_args.o:    unix_args.c ${NAME}.h pgopen.h strfuncs.h useful.h
  861. unix_man.o:    unix_man.c ${NAME}.h strfuncs.h useful.h
  862. vms_args.o:    vms_args.c ${NAME}.h pgopen.h strfuncs.h useful.h
  863. vprintf.o:    vprintf.c useful.h
  864. winsize.o:    winsize.c useful.h
  865. xparse.o:    xparse.c ${NAME}.h strfuncs.h useful.h
  866. X
  867. REMLINE
  868. REM installation dependencies
  869. REMLINE
  870. install: _Pathname(${INCDIR},${NAME}.h) \
  871. X        _Pathname(${LIBDIR},${LIBFILE}) \
  872. X        _Pathname(${LOCAL},${PROGRAM})
  873. X
  874. _Pathname(${INCDIR},${NAME}.h): ${NAME}.h useful.h
  875. X    ( ${CHDIR} ${INCDIR}; ${DEL} ${NAME}.h useful.h )
  876. X    ${COPY} ${NAME}.h useful.h ${INCDIR}
  877. X
  878. _Pathname(${LIBDIR},${LIBFILE}): ${LIBARGS}
  879. X    ${DEL}  _Pathname(${LIBDIR},${LIBFILE})
  880. X    ${COPY} ${LIBARGS}  _Pathname(${LIBDIR},${LIBFILE})
  881. X    ${RANLIB}  _Pathname(${LIBDIR},${LIBFILE})
  882. X
  883. _Pathname(${LOCAL},${PROGRAM}): ${PROGRAM} ${TEMPLATES}
  884. X    ( ${CHDIR} ${LOCAL} ; ${DEL} ${PROGRAM} ${TEMPLATES} )
  885. X    ${COPY} ${PROGRAM} ${TEMPLATES} ${LOCAL}
  886. X
  887. REMLINE
  888. REM maintenance dependencies
  889. REMLINE
  890. lint: ${SRCS}
  891. X    ${LINT} ${LINTFLAGS} ${SRCS}
  892. X
  893. shar: ${NAME}.shar
  894. X
  895. ${NAME}.shar: ${FILES}
  896. X    ${DEL} ${NAME}.shar
  897. X    ${SHAR} ${FILES} _Output(${NAME}.shar)
  898. X
  899. clean:
  900. X    ${DEL} ${OBJS} ${PROG_OBJS} ${TEST_OBJS}
  901. X    ${DEL} tags core .exrc
  902. X
  903. clobber: clean
  904. X    ${DEL} ${LIBARGS}  ${PROGRAM}  ${STYLE}_test
  905. X
  906. tags: ${SRCS} ${HDRS}
  907. X    ${MKTAGS} ${SRCS} ${HDRS}
  908. X
  909. collapse: clobber shar
  910. X    ${SQZ} ${NAME}.shar
  911. X    ${DEL} ${FILES}
  912. X
  913. print: ${SRCS} ${HDRS}
  914. X    @${PRINT} ${SRCS} ${HDRS}
  915. X
  916. SHAR_EOF
  917. chmod 0664 parseargs/Makefile.cpp ||
  918. echo 'restore of parseargs/Makefile.cpp failed'
  919. Wc_c="`wc -c < 'parseargs/Makefile.cpp'`"
  920. test 7778 -eq "$Wc_c" ||
  921.     echo 'parseargs/Makefile.cpp: original size 7778, current size' "$Wc_c"
  922. rm -f _shar_wnt_.tmp
  923. fi
  924. # ============= parseargs/README ==============
  925. if test -f 'parseargs/README' -a X"$1" != X"-c"; then
  926.     echo 'x - skipping parseargs/README (File already exists)'
  927.     rm -f _shar_wnt_.tmp
  928. else
  929. > _shar_wnt_.tmp
  930. echo 'x - extracting parseargs/README (Text)'
  931. sed 's/^X//' << 'SHAR_EOF' > 'parseargs/README' &&
  932. X
  933. X
  934. X
  935. X                                   PARSEARGS
  936. X
  937. X                          extracted from Eric Allman's
  938. X
  939. X                             NIFTY UTILITY LIBRARY
  940. X
  941. X                                 Eric P. Allman
  942. X                            University of California
  943. X                              Berkeley, California
  944. X                               eric@Berkeley.EDU
  945. X
  946. X                                modifications by
  947. X
  948. X                                 Peter da Silva
  949. X                  Ferranti International Controls Corporation
  950. X                               Sugar Land, Texas
  951. X                               peter@ferranti.com
  952. X
  953. X                          modified and rewritten by
  954. X
  955. X                                 Brad Appleton
  956. X                 Harris Corporation, Computer Systems Division
  957. X                         Fort Lauderdale, Florida USA
  958. X                            brad@ssd.csd.harris.com
  959. X
  960. X
  961. X
  962. X SUMMARY
  963. X =======
  964. X This directory contains a subset of a utility library that I have used
  965. X (in various forms) for several years now. This particular version is
  966. X rather sparse, being a relatively recent reimplementation.
  967. X
  968. X [ The rest of the utility library has been left out, to reduce the
  969. X size of Parseargs. The complete set of utilities was pubbed in the
  970. X first comp.sources.misc distribution. -- PDS ]
  971. X
  972. X I am making this available as a  result of the rather surprising
  973. X response to my C  Advisor column in UNIX Review Vol. 7 No. 11 on
  974. X argument parsing, in which I  described an alternative to getopt.
  975. X Several dozen people have asked for the source code -- an amazing
  976. X number, considering that in the four years prior to this column, I
  977. X have gotten perhaps six letters in total.
  978. X
  979. X
  980. X COPY/REUSE POLICY
  981. X =================
  982. X Permission is hereby granted to freely copy and redistribute this
  983. X software, provided that the author is clearly credited in all copies
  984. X and derivations. Neither the name of the author nor that of the
  985. X University may be used to endorse or promote products derived from
  986. X this software without specific written permission. This software is
  987. X provided ``As Is'' and without any express or implied warranties.
  988. X
  989. X
  990. X CONTENTS
  991. X ========
  992. X     README : this file.
  993. X     [ Intro : introduction to parseargs -- BDA ]
  994. X     [ doc/Makefile : makefile for parseargs documentation -- BDA ]
  995. X     [ doc/* : documentation for parseargs -- BDA ]
  996. X     Makefile : a makefile for the library.
  997. X     [ Makefile.cpp : a makefile template -- BDA ]
  998. X     useful.h : a general header file, used by most everything.
  999. X     parseargs.h : headers for the argument parser.
  1000. X     [ parseargs.c is now broken down into the following files : PDS ]
  1001. X         unix_args.c : a command line argument parser. Popular
  1002. X             response to my C Advisor column about this routine
  1003. X             in UNIX Review Vol. 7 No. 11 prompted me to make
  1004. X             this distribution available.
  1005. X         amiga_args.c : Amiga version of unix_args.c -- PDS
  1006. X         ibm_args.c : IBM-PC version of unix_args.c -- BDA
  1007. X         vms_args.c : VAX/VMS version of unix_args.c -- BDA
  1008. X         arglist.c : routines for ARGLIST options. -- PDS
  1009. X         argtype.c : routines for other options. The argument value parsers
  1010. X             for floating point values may be excluded by #defining the
  1011. X             macro NOFLOAT (only if you do NOT need floating-point values).
  1012. X             I had to break this out because RISC/os 4.01 from Mips doesn't
  1013. X             seem to support strtod in the BSD environment. You may find you
  1014. X             need to include -lm for this to work.
  1015. X         strfuncs.[ch] : string-manipulation functions &
  1016. X             dictionary-style searching routines.
  1017. X     [ end of parseargs.c : PDS ]
  1018. X     [ parseargs.c has been resurrected as a command line interface
  1019. X             to the parseargs library routines -- BDA ]
  1020. X     syserr.c : error message printing routines.
  1021. X     stest.c : a small test program for the argument parser.
  1022. X     [ xparse.c : source for [flsv]parseargs() and parsecntl() -- BDA ]
  1023. X     [ unix_man.c : routine to print unix man1 templates -- BDA ]
  1024. X     [ winsize.c : routine to "portably" get the screen size -- BDA ]
  1025. X     [ pgopen.[ch] : Unix source to pipe output to a pager -- BDA ]
  1026. X     [ vprintf.c : portable implementations of vprintf() & vfprintf() ]
  1027. X     [ parseargs.awk : awk interface to parseargs(1) -- BDA ]
  1028. X     [ parseargs.pl : perl interface to parseargs(1) -- BDA ]
  1029. X     [ test.sh : Bourne shell-script to test parseargs(1) -- BDA ]
  1030. X     [ test.csh : C shell-script to test parseargs(1) -- BDA ]
  1031. X     [ test.ksh : Korn shell-script to test parseargs(1) -- BDA ]
  1032. X     [ test.awk : awk script to test parseargs(1) -- BDA ]
  1033. X     [ test.pl : perl script to test parseargs(1) -- BDA ]
  1034. X
  1035. X The parseargs routines really ought to have a way of matching a  list
  1036. X (e.g., return the rest of argv). This isn't especially hard to do, but
  1037. X I haven't gotten around to it yet. [ Added, with ARGLIST flag -- PDS ]
  1038. X
  1039. X [ Added argUsage and argDummy pseudo-argument types -- BDA ]
  1040. X [ Added arg{S,T,U}Bool boolean argument types -- BDA ]
  1041. X [ Added ARGNOVAL argument flag to implement trigger types -- BDA ]
  1042. X [ Added ARGVALOPT, ARGVALREQ, and ARGVALGIVEN argument flags to
  1043. X   implement options with optional arguments -- BDA ]
  1044. X [ Added ARGPOS argument flag to implement arguments that may be
  1045. X    matched both positonally and by keyword -- BDA ]
  1046. X [ Added ARGVEC for argc/argv structures and implemented them for
  1047. X   string, character, floating point, and integer types -- BDA ]
  1048. X [ Added fparseargs(3), sparseargs(3), vparseargs(3), lparseargs(3),
  1049. X   and parsecntl(3) functions for flexibility and robustness -- BDA ]
  1050. X
  1051. X
  1052. X DISCLAIMERS
  1053. X ===========
  1054. X I hacked this code up to (hopefully) work on ANSI C  compilers, since
  1055. X several readers seem to be interested in this sort of thing. I can't
  1056. X claim to have really tested this.
  1057. X [ Now compiles under both BSD & AT&T Unix Systems using both ANSI and
  1058. X   non-ANSI C compilers -- BDA ]
  1059. X
  1060. X The original version was tested under SunOS 4.0 on SPARC
  1061. X architectures. The version you see has been loosely tested on a Mips
  1062. X M/2000 running RISC/os 4.01; I  have only tried it in the BSD
  1063. X environment, and that only loosely.
  1064. X
  1065. X ACKNOWLEDGEMENTS
  1066. X ================
  1067. X I wrote the first version of this code while working at the
  1068. X International Computer Science Institute in Berkeley, CA.
  1069. X
  1070. X ______________________________________________________________________________
  1071. X
  1072. X      Update to parseargs by Peter da Silva (peter@ferranti.com):
  1073. X
  1074. X (2nd update: more improvements to arg parsing, argChar type)
  1075. X (3rd update: return to original calling sequence, argList type)
  1076. X (4th update: removed routines not relevant to parseargs,
  1077. X              removed tracing/interactive stuff.)
  1078. X
  1079. X
  1080. X Parseargs is a really nifty set of routines, but it doesn't fit too
  1081. X well with standard UNIX semantics. In particular, you can get into a
  1082. X lot of trouble using it in a script if it drops into interactive mode
  1083. X on you. Also, it's not as useful as it could be for non-UNIX systems.
  1084. X To make it work better, I've made a couple of changes.
  1085. X
  1086. X It compiled straight out of the box on System III once I'd provided
  1087. X bcopy, bcmp, and strtol. The strtol I've provided is almost totally
  1088. X untested, but hopefully you won't need to use it. It's only for folks
  1089. X with old UNIX systems.
  1090. X
  1091. X First change was to disable the interactive prompting for arguments. I
  1092. X think that's inconsistent with usual UNIX semantics.
  1093. X
  1094. X The second change was to allow for a trailing list of arguments. I
  1095. X originally implemented this by changing the calling sequence to
  1096. X parseargs. On reflection this would just produce incompatibilities, so
  1097. X I added a  new flag, ARGLIST, and a new type, listStr. Later, other
  1098. X kinds of lists can presumably be added. A list handles a pointer to a
  1099. X list of objects:
  1100. X
  1101. X     struct arglist *fred;
  1102. X
  1103. X Operations are defined on arglists, L_NEXT(fred) produces the next
  1104. X element in fred. L_STRING(fred) produces the value of fred cast to
  1105. X "char *".
  1106. X
  1107. X During evaluation the list is kept in LIFO order, and it's reversed
  1108. X just before returning to parseargs. This simplifies the coding of the
  1109. X list routines, but still lets you step through the list in a
  1110. X reasonable order. [ lists are now maintained in FIFO order --BDA ]
  1111. X
  1112. X The final change is the addition of a  'argChar' type. This parses
  1113. X character arguments (such as the '-T' option to 'awk'), accepting
  1114. X single characters,
  1115. X
  1116. X Parseargs itself no longer uses ckalloc, traceset, funclist, and so
  1117. X on. these routines are pretty cool, but when you're grafting parseargs
  1118. X onto an existing program they just get in the way. Also, it's possible
  1119. X to make parseargs fail in a cleaner fashion by handling out-of-memory
  1120. X cases myself. Certainly there's not going to be any loose memory lying
  1121. X around to be collected when parseargs starts up!
  1122. X
  1123. X Also, the error messages have been made a  bit more descriptive.
  1124. X Instead of saying "stest: value required for -c flag", it prints
  1125. X "stest: RepCount required for -c flag". The ad_prompt element should
  1126. X really be a descriptive word that can be used in a sentence... or for
  1127. X non_UNIX systems a multi-character or keyword based flag. I have an
  1128. X Amiga version included, for example, that uses keyword syntax. In that
  1129. X version, the usage message reads:
  1130. X
  1131. X     Usage: amiga_test <name> [GROUP <newsgroup>]... [REP <repcount>] +
  1132. X             [DIR <dirname>] [X] [Y] [Z] [TAB <tabchar>] [<file>]...
  1133. X
  1134. X Instead of:
  1135. X
  1136. X     Usage: unix_test <Name> [-n <newsGROUP>]... [-c <REPcount>] [-d <DIRname>] [-x] [-y] [-z] [-t <TABchar>] [<File>]...
  1137. X
  1138. X
  1139. X This would solve the old problem of UNIX programs sticking out like a
  1140. X sore thumb in other operating systems.
  1141. X
  1142. X The Amiga version still needs to prompt for options if called with a
  1143. X single types and finally integrate CLI and Workbench environments.
  1144. X
  1145. X Latest update: the prompt string may include a more extensive comment
  1146. X (in parentheses, after the one-word initial comment), that will be
  1147. X used in error messages and listed in the usage message.
  1148. X
  1149. X [ comment may appear in square brackets, curly braces, angle brackets,
  1150. X   or parentheses (so one can use the other 3 in the comment) -- BDA ]
  1151. X
  1152. X The environment variable USAGE controls the printing of the usage
  1153. X message:
  1154. X
  1155. X     USAGE == -1 No usage message.
  1156. X     USAGE == 0 Short message (default).
  1157. X     USAGE == 1 Names of flags given in parentheses.
  1158. X     USAGE == 2 Long description of options given.
  1159. X     USAGE == 3 Both flag names and long description given.
  1160. X
  1161. X Examples:
  1162. X
  1163. X     $ USAGE=3; export USAGE
  1164. X     $ unix_test -c
  1165. X     unix_test: REPcount (number of times to repeat each group) required for -c flag
  1166. X     unix_test: Name required
  1167. X     Usage: unix_test <Name> [-n <newsGROUP>]... [-c <REPcount>] [-d <DIRname>] [-x] (Xflag) [-y] (Yflag) [-z] (Zflag) [-t <TABchar>] [<File>]...
  1168. X     Options:
  1169. X             -n newsGROUP newsgroups to test
  1170. X             -c REPcount number of times to repeat each group
  1171. X             -x (Xflag) expand in X direction
  1172. X             -y (Yflag) expand in Y direction
  1173. X             -z (Zflag) expand in Z direction
  1174. X     $ USAGE=0; export USAGE
  1175. X     $ unix_test
  1176. X     unix_test: Name required
  1177. X     Usage: unix_test <Name> [-n <newsGROUP>]... [-c <REPcount>] [-d <DIRname>] [-x] [-y] [-z] [-t <TABchar>] [<File>]...
  1178. X     $ USAGE=-1; export USAGE
  1179. X     $ unix_test
  1180. X     unix_test: Name required
  1181. X
  1182. X
  1183. X [ changed to use the environment variable USAGECNTL instead of USAGE.
  1184. X   "USAGE" is a variable name commonly used in shell scripts. --BDA ]
  1185. X
  1186. X [ when keywords are desired (via USAGECNTL) their actual command-line
  1187. X   syntax is now displayed (instead of just appearing in parentheses)
  1188. X   -- BDA ]
  1189. X
  1190. X ______________________________________________________________________________
  1191. X
  1192. X
  1193. X             Update to parseargs (and major re-write) by Brad Appleton
  1194. X                        (brad@travis.ssd.csd.harris.com)
  1195. X                              Last Update: 03/01/91
  1196. X
  1197. X DISCLAIMER
  1198. X ==========
  1199. X Neither Brad Appleton, nor Harris Corporation (including any of its
  1200. X subsidiaries and subdivisions and Harris Computer Systems Division in
  1201. X particular) are responsible for maintaining and supporting this
  1202. X software or for any consequences resulting from the use of this
  1203. X software, no matter how awful, even if they arise from flaws in the
  1204. X software.
  1205. X
  1206. X
  1207. X NEW FILES: parseargs.c, xparse.c, pgopen.[ch], vprintf.c
  1208. X ========================================================
  1209. X I thought parseargs was so cool that I wanted to be able to use it for
  1210. X shell-scripts too! To do that I would need a command-line interface.
  1211. X I decided to make the command-line interface look as close as possible
  1212. X to the C-interface so I  basically implemented a  very small
  1213. X interpreter; Hence, parseargs.c was resurrected but this time as an
  1214. X interface to the parseargs library instead of being the guts of it.
  1215. X
  1216. X Xparse.c implements routines to parse arguments from a   file
  1217. X (fparseargs), from an arglist (lparseargs), from a  string
  1218. X (sparseargs), from a variable argument-list (vparseargs), and from a
  1219. X string-vector (parseargs). It also contains the routine parsecntl()
  1220. X which controls the parsing behavior of a  commands, and the routine
  1221. X usage() which prints a usage message. Each of the <os>_args.c files
  1222. X used to implement its own parseargs() and usage() functions, this has
  1223. X been changed so that parseargs() and usage() are implemented in
  1224. X xparse.c and the guts of the os-specific parsing and formatting is
  1225. X implemented in the routines <os>_parse() and <os>_usage() in the file
  1226. X <os>_args.c!
  1227. X
  1228. X On Unix systems, if the user desires, usage messages are paged using
  1229. X popen(3S). The pager used is ${USAGE_PAGER:-${PAGER:-/usr/ucb/more}}.
  1230. X If for some reason this fails then no paging is performed. The pager
  1231. X library is implemented in the file pgopen.c and only used if the macro
  1232. X USE_PAGER is #defined. Pgopen.h is an include file which will include
  1233. X the external declarations for pgopen.c if USE_PAGER is #defined and
  1234. X defines some functionally equivalent (but non-paging) macros instead.
  1235. X
  1236. X The file vprintf.c is a  portable implementation of vprintf(),
  1237. X vfprintf(), and vsprintf() for systems (such as BSD Unix) that don't
  1238. X already have them.
  1239. X
  1240. X
  1241. X NEW ARGUMENT TYPES: argUsage, arg[UTS]Bool, & argDummy
  1242. X ======================================================
  1243. X I added the following argument types to parseargs:
  1244. X
  1245. X    argUsage -- print a usage message
  1246. X    argDummy -- dummy argument, not parsed but used for messages
  1247. X    argSBool -- set a boolean flag
  1248. X    argTBool -- toggle a boolean flag
  1249. X    argUBool -- unset a boolean flag
  1250. X
  1251. X Consult the manual page for argtype(3) for more information.
  1252. X I also added the capability to handle ARGVEC arguments into the
  1253. X remaining argument type functions.
  1254. X
  1255. X NEW ARGUMENT FLAGS:
  1256. X ===================
  1257. X I added the following argument flags to parseargs:
  1258. X
  1259. X     ARGPOS -- arg is positionally matched and keyword matched
  1260. X     ARGNOVAL -- arg takes no value
  1261. X     ARGVALOPT -- arg takes an optional value
  1262. X     ARGVALREQ -- arg requires a value
  1263. X     ARGGIVEN -- arg was supplied on command-line
  1264. X     ARGVALGIVEN -- arg-value was supplied on command-line
  1265. X     ARGDESCRIBED -- argument was given a description
  1266. X     ARGKEYWORD -- argument was matched as a keyword
  1267. X     ARGVALSEP -- arg-value was in a separate token from the argument
  1268. X
  1269. X Consult the manual page for parseargs(1) & parseargs(3) for more information.
  1270. X
  1271. X NEW INTERFACE
  1272. X =============
  1273. X I added a set of Macros to allow a more "self documenting" approach to
  1274. X declaring argument-descriptor arrays. The "old-style" is still
  1275. X accepted (but if used it is recommended that the STARTOFARGS macro is
  1276. X used in conjunction with ENDOFARGS). The new style is documented in the
  1277. X parseargs(3) manual under the heading "CMD MACROS"
  1278. X
  1279. X
  1280. X MODIFICATIONS TO USAGE MESSAGES
  1281. X ===============================
  1282. X After Peter modified usage() to look at the USAGE environment
  1283. X variable, I decided that, even if the user had turned USAGE off, that
  1284. X (s)he really did want the usage if an argUsage option was specified so
  1285. X I added a  static global Usage_Requested to xparse.c to over-ride
  1286. X the USAGE variable (if necessary) so that a verbose message is always
  1287. X given when an argUsage option is specified (regardless of the value in
  1288. X the environment variable).
  1289. X
  1290. X I also changed the name of the environment variable that gets "looked"
  1291. X up to be USAGECNTL instead of USAGE since USAGE is a common variable
  1292. X name for shell scripts. Furthermore, I changed the contents of USAGECNTL
  1293. X from a number to a sequence of mnemonic strings (for better readability).
  1294. X I also made USAGECNTL control whether or not a command-description is
  1295. X printed and whther or not the message is piped to a pager on Unix.
  1296. X
  1297. X Under VMS, the global symbol USAGECNTL is used in lieu of an environment
  1298. X variable.  See the parseargs(3) and parseargs(1) manual pages for more
  1299. X information regarding USAGECNTL.
  1300. X
  1301. X SPECIFYING ALTERNATE PARSING BEHAVIOR
  1302. X =====================================
  1303. X Parseargs provides 3 methods for controlling "how" the command-line is
  1304. X parsed. There is a parsecntl() function which may be used to specify
  1305. X flags other than the default parse-behavior. The user may define the
  1306. X environment variable (or global symbol) PARSECNTL to contain the option-
  1307. X string that corresponds to the desired combination of pa_XXXX flags
  1308. X #defined in parseargs.h. The parseargs command, also allows for options
  1309. X to specify certain parsing behavior. The parsecntl() function provides
  1310. X finer control than either of the other two methods. The user's PARSECNTL
  1311. X variable will always over-ride any conflicting flags that were set by
  1312. X parsecntl() or by the parseargs command via command-line options.
  1313. X See the manual pages for parseargs(1), parseargs(3), and parsecntl(3)
  1314. X for more information.
  1315. X
  1316. X GIVING DEFAULT ARGUMENTS
  1317. X ========================
  1318. X Programs that use parseargs may be given default arguments under UNIX
  1319. X and PCs through the use of environment variables (symbols are used for
  1320. X VMS systems). If a C-program or a shell-script uses parseargs to imple-
  1321. X ment a command named "foo" then the environment variable (or global
  1322. X synbol) FOO_ARGS will be parsed for any "default" arguments before argv
  1323. X is parsed.  Argv will over-ride any options that are specified in
  1324. X FOO_ARGS (except that ARGLISTs and ARGVECs set in FOO_ARGS will be
  1325. X appended from argv[]).
  1326. X
  1327. X
  1328. X SPECIFYING DEFAULT ARGDESCs TO SEARCH
  1329. X =====================================
  1330. X If a given option/qualifier does not appear to match any items in the
  1331. X argdesc-array, a  default argdesc-array is then searched to match the
  1332. X option. If it is STILL unmatched then it is flagged as such. The
  1333. X default-argdesc array is automatically used by all programmer-defined
  1334. X argdesc-array but may be unset or reset using the pc_DEFARGS function
  1335. X of parsecntl(3).
  1336. X
  1337. X
  1338. X ADDING NEW SHELLS TO parseargs(1)
  1339. X =================================
  1340. X I did my best to implement parseargs.c in a manner that would make it
  1341. X relatively easy to add new shell-types. At this point in time, parseargs
  1342. X will generate output for the following command-interpreters:
  1343. X
  1344. X     sh           (Bourne Shell)
  1345. X     csh/tcsh     (C-Shell)
  1346. X     bash         (Bourne-Again Shell)
  1347. X     ksh          (Korn Shell)
  1348. X     rc           (Plan 9 Shell)
  1349. X     perl
  1350. X     awk
  1351. X
  1352. X Parseargs.c thinks the Free Software Foundation's Bourne-Again Shell
  1353. X (bash) is equivalent to the Bourne shell (sh). Bash is a superset of
  1354. X sh (so I am told) but I do not know enough about it to treat it
  1355. X differently. I  hope someone who is familiar with bash syntax will
  1356. X correct this deficiency (particularly with shell arrays).
  1357. X
  1358. X If someone wants to try to add more shell-types to parseargs.c, here
  1359. X are the main things that need to be done:
  1360. X
  1361. X 1. add #defines for both the name (a string) and type (an integer) of
  1362. X    shell (e.g #define BOURNE_SHELL "sh" and #define SH 4)
  1363. X
  1364. X 2. add a shell_info entry into the array Shell[]. The index of the
  1365. X    entry in the array should be the number used in the #define for the
  1366. X    type of shell.
  1367. X
  1368. X 3. make sure that get_shell_type() will return the proper value for
  1369. X    the new shell.
  1370. X
  1371. X 4. print_args doesnt really do any shell specific stuff outside of
  1372. X    indexing into the table. The print_arglist() and
  1373. X    unset_positional_parameters() functions do some shell specific stuff
  1374. X    and will need a case added to the switch statement(s) for the newly
  1375. X    added shell.
  1376. X
  1377. X 5. If the information in the shell-info structure is not sufficient
  1378. X    for the new shell then you should either:
  1379. X       a) redefine the structure for all shells including your shell.
  1380. X       b) add some special code into print_args() for your shell!
  1381. X
  1382. X For a more thorough discussion of parseargs(1), consult the manual pages!
  1383. X
  1384. X
  1385. X MODIFICATIONS TO KEYWORD MATCHING
  1386. X =================================
  1387. X I changed keyword matching in strfuncs.c just a tad by allowing only a
  1388. X partial match on the keyword (instead of a full match), this way the
  1389. X user only needs to give enough of the keyword on the command line so
  1390. X that it will uniquely match a  suffix of a  keyword in the arg-
  1391. X descriptor table. A drawback to this is that if the user does NOT
  1392. X specify enough of the keyword to uniquely match ONE arg-desc entry,
  1393. X then the first such entry encountered will be considered to match the
  1394. X partial keyword on the command-line.
  1395. X
  1396. X This "shortest-prefix" matching is performed 1st on only the uppercase
  1397. X characters in the ad_prompt, and then (if no match) on the whole
  1398. X prompt. This is "nice" in that the user only needs to specify the
  1399. X shortest prefix but it also means that a typo can very easily be
  1400. X interpreted as an option when it shouldnt be (both "+new" and "+gr"
  1401. X would match "newsGROUPS") or the wrong option may be matched if too
  1402. X small a portion of the keyword is provided.
  1403. X
  1404. X To help prevent this type of thing... Unless the keyword to be matched
  1405. X has length < 2, I force the user to specify at least 2 characters for
  1406. X the keyword (for VAX/VMS this minimum length becomes 4 iff the keyword
  1407. X starts with "NO").
  1408. X
  1409. X amiga_args.c still uses the old keyword matching function. Since
  1410. X AmigaDOS keywords have no '/' or '-' prefix -- I thought it would be
  1411. X too dangerous to allow such "partial matching" because it would be too
  1412. X easy for bona-fide arguments to partially match a keyword!
  1413. X
  1414. X
  1415. X MODIFICATIONS TO CHARACTER ARGTYPES
  1416. X ===================================
  1417. X Under UNIX, an argChar option argument may now be provided on the
  1418. X command-line immediately following the option-letter and the
  1419. X characters following the character argument are still processed as
  1420. X options. Hence, if '-c' is an argChar option and '-x', '-y', and '-z'
  1421. X are boolean options, then we may specify the character '_' as an
  1422. X argument to '-c' as well as specifying the '-x', '-y' and '-z' flags
  1423. X in the following manner:
  1424. X
  1425. X     -c_xyz
  1426. X
  1427. X Of course, the following will have the same effect:
  1428. X
  1429. X     -c_ -xyz
  1430. X
  1431. X as will this:
  1432. X
  1433. X     -c _ -xyz
  1434. X
  1435. X but the following is incorrect:
  1436. X
  1437. X     -c _xyz
  1438. X
  1439. X In other words, only the character that immediately follows an argChar
  1440. X option is considered to be an argument to the option and other option
  1441. X characters may immediately precede the single-character argument.
  1442. X
  1443. X
  1444. X MODIFICATIONS TO BOOLEAN ARGTYPES
  1445. X =================================
  1446. X Boolean types may now take an argument if so desired. under VAX/VMS:
  1447. X
  1448. X     "/FLAG" (1)
  1449. X
  1450. X will turn ON an an argBool or argSBool flag, will turn OFF an argUBool
  1451. X flag, and will toggle an argTBool flag. However, the following:
  1452. X
  1453. X     "/FLAG=ON" (2)
  1454. X
  1455. X will turn ON the flag regardless of whether it is argBool, argSBool,
  1456. X argUBool, or argTBool (so long as it is one of them). Similarly,
  1457. X
  1458. X     "/FLAG=OFF" (3)
  1459. X
  1460. X will always turn a boolean flag OFF!
  1461. X
  1462. X Similar syntax is used for AmigaDOS, the corresponding Amiga
  1463. X specification for examples (1)-(3) above would be:
  1464. X
  1465. X     FLAG (1)
  1466. X     FLAG=ON (2)
  1467. X     FLAG=OFF (3)
  1468. X
  1469. X For the Amiga, the boolean argument MUST be part of the same argv[]
  1470. X element as the keyword itself ("FLAG ON" or "FLAG OFF" is not
  1471. X acceptable).
  1472. X
  1473. X For Unix (and IBM-PCs), long option examples of (1)-(3) would be the
  1474. X following:
  1475. X
  1476. X     +flag (1)
  1477. X     +flag=on (2)
  1478. X     +flag=off (3)
  1479. X
  1480. X As with the Amiga, the boolean argument ("on" or "off") MUST be part
  1481. X of the same argv[] element as the long-option itself.
  1482. X
  1483. X For single character options under Unix, the corresponding examples
  1484. X for (1)-(3) are as follows:
  1485. X
  1486. X     -f (1)
  1487. X     -f+ (2)
  1488. X     -f- (3)
  1489. X
  1490. X As with Unix, the boolean argument ("on" or "off") MUST be part of the
  1491. X same argv[] element as the long-option itself.
  1492. X
  1493. X For single character options under MS-DOS and OS/2, the corresponding
  1494. X examples for (1)-(3) are as follows:
  1495. X
  1496. X     /f (1)
  1497. X     /f+ (2)
  1498. X     /f- (3)
  1499. X
  1500. X With single character options, any boolean argument must be a  single
  1501. X character and must be in the character immediately following the the
  1502. X option character. If the character following the option character is
  1503. X NOT one of '-', '+', '0', ment) then the default action will be taken
  1504. X (set, clear or toggle depending upon the type of boolean flag) and the
  1505. X character immediately following the boolean option is assumed to be
  1506. X another option-specification (e.g. -fc4 and -f+c4 are both allowed
  1507. X where 'f' is a boolean flag and 'c' is an integer (argInt) flag).
  1508. X
  1509. X With all supported operating systems, the following arguments may be
  1510. X used as Boolean arguments (differences between uppercase/lowercase are
  1511. X ignored):
  1512. X
  1513. X      Arg        Effect
  1514. X     =====  ====================
  1515. X       ^    Toggles flag (single character options only)
  1516. X       ~    Toggles flag (single character options only)
  1517. X       1    Sets flag
  1518. X       0    Unsets flag
  1519. X       +    Sets flag
  1520. X       -    Unsets flag
  1521. X       T    Sets flag
  1522. X       F    Unsets flag
  1523. X      YES   Sets flag
  1524. X       NO   Unsets flag
  1525. X       ON   Sets flag
  1526. X      OFF   Unsets flag
  1527. X     TRUE   Sets flag
  1528. X    FALSE   Unsets flag
  1529. X
  1530. X With single character options under Unix and IBM-PCs, only '+', '-',
  1531. X '0', '1', '^' and '~' may be used.
  1532. X
  1533. X
  1534. X CHANGES TO ARGTYPE RETURN VALUES
  1535. X ================================
  1536. X In order to allow only a single character to be consumed for arguments
  1537. X to boolean and character options, I  had to change the way return
  1538. X values from an argtype function were handled. Previously, the argtype
  1539. X function merely returned TRUE (1) upon success and FALSE (0) upon
  1540. X failure. I changed this slightly. Now, an argument type function
  1541. X returns:
  1542. X
  1543. X     FALSE (0) if the argument was NOT successfully interpreted
  1544. X
  1545. X     TRUE (1) if the argument was successfully interpreted and ALL
  1546. X             characters of the argument were used.
  1547. X
  1548. X     -N (<0) if the argument was successfully interpreted AND only
  1549. X             the first N characters of the argument were used.
  1550. X
  1551. X At this time, only the Boolean and argChar argument type functions
  1552. X return any value other than TRUE or FALSE.
  1553. X
  1554. X
  1555. X NEW ARGUMENT LISTS
  1556. X ==================
  1557. X Arglists have been enhanced with a new type called arg-vectors (and
  1558. X use the ARGVEC flag instead of the ARGLIST flag). Arg-vectors are a
  1559. X structure containing an argv/argc pair. There are two macros in
  1560. X parseargs.h which are used for arg-vectors. ARGVEC_T may be used to
  1561. X declare a vector structure or a vector type; ARGVEC_EMPTY may be used
  1562. X to initialize the structure. It is strongly recommended that ARGVEC_T
  1563. X be used to declare vector types in a typedef statement (particularly
  1564. X if one is using function prototypes) but for those who insist, it may
  1565. X be used to directly declare a  structure. An example of both uses (as
  1566. X well as an example use of ArgLists) may be found in the documentation.
  1567. X
  1568. X
  1569. X MISCELLANEOUS FIXES/ENHANCEMENTS
  1570. X ================================
  1571. X unix_args.c did not consider '-' or '+' to be valid arguments unless
  1572. X '--' had already been specified. This has been fixed.
  1573. X
  1574. X The compile-time interactive option seemed to have been removed from
  1575. X parseargs so I put it back in and made it a run-time option (that is
  1576. X selected using the pa_PROMPT function-code to parsecntl()). I  also
  1577. X made it prompt repeatedly for arglists (a blank line ends the list).
  1578. X No characters are escaped or trimmed (such as whitespace, quotes, or
  1579. X special characters) when a prompted argument is read from the user!
  1580. X
  1581. X amiga_args.c will now check to see if an argument matches a  keyword
  1582. X before assigning it as a keyword argument. If 'STRING' is an argStr
  1583. X and 'REP' is an argInt then: "cmd STRING REP=4" will leave string
  1584. X without a  value and assign REP to be 4. Previously, this would have
  1585. X resulted in assigning the value of optional keyword arguments.
  1586. X
  1587. X Arglists are no longer stored in LIFO order and then reversed at the
  1588. X last minute, they are now always stored in FIFO order (the order given
  1589. X on the command-line).
  1590. X
  1591. X I also provided extensive updating to the manual pages so that they
  1592. X now reflect the current capabilities of parseargs!
  1593. X
  1594. X
  1595. X MODIFICATIONS TO parseargs.h
  1596. X ============================
  1597. X I hacked parseargs.h up a bit so that certain items may be excluded or
  1598. X included by #defining certain names before including the file.
  1599. X
  1600. X If PARSEARGS_PRIVATE is #defined, then various type and macro
  1601. X definitions which are specific to the implementation of parseargs (but
  1602. X not to its use) are included. This is my hack at C++ friend functions;
  1603. X A file declares itself to be a  "friend" by #defining PARSEARGS_PRIVATE
  1604. X before #including the file parseargs.h
  1605. X
  1606. X If PARSEARGS_NEXTERNS is #defined, then the external function declarations
  1607. X for the various parseargs functions (parseargs, parsecntl, fparseargs,
  1608. X etc ...) are NOT included. This is really only useful to the files that
  1609. X actually implement the various parseargs functions.
  1610. X
  1611. X If PARSEARGS_NARGTYPES is #defined, then the external function
  1612. X declarations for the various argtype functions (argInt, argStr,
  1613. X listStr, etc ..) are NOT included. This is really only useful to the
  1614. X files that actually implement the various argtype functions.
  1615. X
  1616. X Also, ARGDESC is now a typedef instead of a #define. On the same note,
  1617. X arglists may be declared by using the "ArgList" typedef or by using
  1618. X the "struct arglist" structure declaration.
  1619. X
  1620. X
  1621. X MODIFICATIONS TO THE ARGDESC ARRAY
  1622. X ==================================
  1623. X Before I got my hands on it - parseargs had no parsecntl() or means of
  1624. X parsing arguments from a file or a string. Any and all arguments to be
  1625. X parsed would be handled in a single invocation of parseargs. In order
  1626. X to allow arguments to be parsed using multiple passes (which would be
  1627. X required if we were to parse arguments in a file for example) I  added
  1628. X the notion of parse-flags to modify parsing behavior. Because of this,
  1629. X I also required certain local variables to now be static. In order to
  1630. X allow parsing for multiple commands - I put the parse-flags and the
  1631. X static variables into the argument descriptor array itself. This way -
  1632. X each arg-descriptor has its own set of flags and state variables to
  1633. X record its own context.
  1634. X
  1635. X To implement this without changing the existing syntax, I put all this
  1636. X stuff into the FIRST & LAST argument descriptors in the array. If an
  1637. X argdesc-array is declared using the CMD_XXXXX macros, then this is
  1638. X already taken care of. If an argdesc array is used using the old-style
  1639. X syntax, ENDOFARGS will now define two arg-descs at the end of the
  1640. X array. Parseargs needs to recognize the old syntax and shift each
  1641. X element in the array down by one position (creating room for a new one
  1642. X at the top). I would have preferred to just swap the first and last
  1643. X entries in this case but I have to preserve the original order of any
  1644. X positionally-matched parameters! This means that extra pre-processing
  1645. X (to shift the array) needs to be performed for argdesc-arrays that are
  1646. X declared using the old syntax! To avoid this overhead - users of the
  1647. X old syntax could use the pre#defined macro STARTOFARGS and make it the
  1648. X first entry in the argdesc-array.
  1649. X
  1650. X Also, each arg-descriptor is now precompiled so that the argument
  1651. X prompt and the argument description are stored in two separate strings
  1652. X (the first of which is pointed to by the "ad_prompt" field). This
  1653. X avoids the need to constantly write code to "locate" the description
  1654. X every time it is desired by the programmer.
  1655. X
  1656. X In order to ease the use of the various attributes of arg-descriptors,
  1657. X (including the argument-prompt and the argument description) a set of
  1658. X macros is available for extracting the corresponding attributes of a
  1659. X command, or one of its argument entries.  Public macros are documented
  1660. X in the manual pages, private ones are listed here:
  1661. X
  1662. X     cmd_name(Args) -- the given command-name
  1663. X     cmd_flags(Args) -- the command parse flags
  1664. X     cmd_context(Args) -- pointer to the command-context
  1665. X                          (which is stored in the last argument-descriptor)
  1666. X     cmd_state(Args) -- the command-state flags
  1667. X     cmd_list(Args) -- pointer to currently active arg-list
  1668. X     cmd_prev(Args) -- pointer to previously matched arg (Amiga only)
  1669. X     cmd_defargs(Args) -- pointer to default argdesc for this command
  1670. X     cmd_argv0(Args) -- pointer to argv[0] from command-line
  1671. X     cmd_purpose(Args) -- one-line description of command
  1672. X     cmd_description(Args) -- multi-line description of command
  1673. SHAR_EOF
  1674. true || echo 'restore of parseargs/README failed'
  1675. fi
  1676. echo 'End of  part 1'
  1677. echo 'File parseargs/README is continued in part 2'
  1678. echo 2 > _shar_seq_.tmp
  1679. exit 0
  1680. exit 0 # Just in case...
  1681. -- 
  1682. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  1683. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  1684. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  1685. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  1686.